package com.minhua.jijiehao2.mainframe.launcher.forgetpasswordactivity.impl

import com.minhua.jijiehao2.base.BaseMvpPresenter
import com.minhua.jijiehao2.bean.BaseBean
import com.minhua.jijiehao2.bean.CheckCodeBean
import com.minhua.jijiehao2.constants.DefineKey
import com.minhua.jijiehao2.constants.HttpConst
import com.minhua.jijiehao2.http.CallBack
import com.minhua.jijiehao2.http.ParamsMap
import com.minhua.jijiehao2.mainframe.launcher.forgetpasswordactivity.imp.IForgetPasswordPresenter
import com.minhua.jijiehao2.mainframe.launcher.forgetpasswordactivity.imp.IForgetPasswordView
import com.minhua.jijiehao2.utils.InputUtils
import com.minhua.jijiehao2.utils.T

internal class ForgetPasswordPresenter : BaseMvpPresenter<IForgetPasswordView>(), IForgetPasswordPresenter {

    private var mForgetPasswordModel = ForgetPasswordModel()

    override fun sendCode() {
        val userName = v?.getUserName() ?: ""
        if (!InputUtils.checkCellphone(userName)) {
            v?.onUserNameError()
            return
        }

        val map = ParamsMap()
        map.put(DefineKey.PHONE, userName)
        map.put(DefineKey.CHECK_TYPE, DefineKey.FORGOT_CODE)
        mForgetPasswordModel.sendCode(map, object : CallBack<CheckCodeBean>() {
            override fun onSuccess(t: BaseBean<CheckCodeBean>) {
                val data = t.data
                if (data?.state ?: "" == HttpConst.STATE_10) {
                    v?.onSendCodeSuccess(t.msg ?: "")
                } else {
                    T.showShort(data?.message)
                }
            }
        })
    }

}